package com.power.leetcode;

import java.util.Stack;

/**
 * @description:
 * @author: jiangnan
 * @time: 2021/6/7 6:59 下午
 */
public class Solution_20 {


    protected Stack stack = new Stack();

    public boolean isValue(String s) {
        if (s.isEmpty()) {
            return false;
        }
        char[] t = s.toCharArray();
        for (int i = 0; i < t.length; i++) {
            if (t[i] == '{' || t[i] == '[' || t[i] == '(') {
                push(t[i]);
                continue;
            } else if (t.length == 0 || (char) stack.pop() != t[i]) {
                return false;
            }/*else if (t[i] == ')') {
                char value = (char) stack.pop();
                if (t[i] == value) {
                    continue;
                } else {
                    return false;
                }
            } else if (t[i] == '}') {
                char value = (char) stack.pop();
                if (t[i] == value) {
                    continue;
                } else {
                    return false;
                }

            } else if (t[i] == ']') {
                char value = (char) stack.pop();
                if (t[i] == value) {
                    continue;
                } else {
                    return false;
                }
            } else {
                return false;
            }*/
        }
        return true;
    }

    public void push(char c) {
        if (c == '(') {
            stack.push(')');
        } else if (c == '{') {
            stack.push('}');
        } else {
            stack.push(']');
        }
    }

    public static void main(String[] args) {
        Solution_20 solution = new Solution_20();
        System.out.println(solution.isValue("()"));
        System.out.println(solution.isValue("{)"));
        System.out.println(solution.isValue("{()()[][](){}}"));
    }
}
//leetcode submit region end(Prohibit modification and deletion)
